<?php

/***  DOCUMENTATION LAYER

Klenwell HtmlValidator Unit Test

Last Update: Sep 2007
  
DESCRIPTION
  testing the new validator
  
NOTES
  $test_root dynamically sets root in order to keep tests working after
  they are moved to the __REPOSITORY directory
    
______________________________________________________________________________*/

$_tx0 = microtime();
$test_root = ( strpos(dirname(__FILE__), 'repository') === false ) ? '' : '../';


// Test Name
$test_name = 'sample test';

// Include Files
require_once('html_validator.class.php');

// Configure Test
$debug = 1;


// Test Procedure

// the test data
$HTML[] = <<<HTML
This is a <i>test</i>.  This is in <b>bold.</b>
<div style="color:orange;">Some text with styling</div>
Now some <a>faulty <p>xhtml.</a></p>
HTML;

$HTML[] = <<<HTML
<div>
<p>this is perfect valid.</p>
<a href="/" title="title">a link with a title</a>
</div>
HTML;

$HTML[] = <<<HTML
how about self-closing tags, like:
<hr />
and br: <br />
do they validate?
HTML;

$HTML[] = <<<HTML
let's put a block tag in an inline:
<a href="/"><div>div</div></a>
<blockquote>inner harmony</blockquote>
<span><blockquote>inner harmony</blockquote></span>
HTML;

$HTML[] = <<<HTML
a list:
<ul>
<li>one little</li>
<li>one little</li>
<li>one little</li>
<li>one little</li>
</ul>
HTML;


$HTML[] = <<<HTML
a fake tag:
<fake>
<p>fake stuff</p>
</fake>
HTML;



// run tests
$n = 0;
foreach ( $HTML as $_html )
{
  $n++;
  print "<h2>test #$n</h2>";
  $before = htmlspecialchars($_html);
  $Validator[$n] = new HtmlValidator($debug);
  $Validator[$n]->validate($_html);
  
  if ( $Validator[$n]->is_valid() ) $Validator[$n]->print_d('html is valid', 'green');
  else $Validator[$n]->print_d('html is invalid', 'red');
  
  $prompt = $Validator[$n]->get_prompt('html is invalid','html is valid');
  
  print "<pre style='background:#ccc;'><h4>text</h4>{$before}</pre>";
  print "<pre style='background:#ffc;'><h4>prompt</h4>{$prompt}</pre>";
  print "<pre style='background:#fcc;'><h4>errors</h4>".print_r($Validator[$n]->ERROR,1)."</pre>";
  
  $Validator[$n]->reset();
}






// Footer
$_txn = microtime();
$stx = number_format(((substr($_txn,0,9)) + (substr($_txn,-10)) - (substr($_tx0,0,9)) - (substr($_tx0,-10))),4); 
echo "<h6>test '$test_name' complete in $stx s</h6>";
?>
